Add _ostree_repo_mode_is_bare helper
authorAlexander Larsson <alexl@redhat.com>
Wed, 22 Mar 2017 10:52:41 +0000 (11:52 +0100)
committerAtomic Bot <atomic-devel@projectatomic.io>
Mon, 27 Mar 2017 13:48:41 +0000 (13:48 +0000)
This cleans up some existing code, but it also allows us to later
add new bare modes.

Closes: #750
Approved by: cgwalters

src/libostree/ostree-core-private.h
src/libostree/ostree-repo-checkout.c
src/libostree/ostree-repo-commit.c
src/libostree/ostree-repo.c

index cfd8a998cbd30acdde73997070d9ba60365cf76f..fbd9490e0573eba3f30531700dd7a8416b4495c5 100644 (file)
@@ -139,6 +139,14 @@ _ostree_loose_path (char              *buf,
 #define _OSTREE_METADATA_GPGSIGS_NAME "ostree.gpgsigs"
 #define _OSTREE_METADATA_GPGSIGS_TYPE G_VARIANT_TYPE ("aay")
 
+static inline gboolean
+_ostree_repo_mode_is_bare (OstreeRepoMode mode)
+{
+  return
+    mode == OSTREE_REPO_MODE_BARE ||
+    mode == OSTREE_REPO_MODE_BARE_USER;
+}
+
 GVariant *
 _ostree_detached_metadata_append_gpg_sig (GVariant   *existing_metadata,
                                           GBytes     *signature_bytes);
index 7ae7cd5589287166939088fb2e9660cd873dfd71..5611e6e940208ef72689785b36ae68a956fe1300 100644 (file)
@@ -363,7 +363,7 @@ checkout_file_hardlink (OstreeRepo                          *self,
                         GError                             **error)
 {
   HardlinkResult ret_result = HARDLINK_RESULT_NOT_SUPPORTED;
-  int srcfd = (self->mode == OSTREE_REPO_MODE_BARE || self->mode == OSTREE_REPO_MODE_BARE_USER) ?
+  int srcfd = _ostree_repo_mode_is_bare (self->mode) ?
     self->objects_dir_fd : self->uncompressed_objects_dir_fd;
 
  again:
index 7a641de8331f014ef9dcfa09f6ada9817cfff8d3..1308ef5cf99f4c60091625cee654decbcee4d109 100644 (file)
@@ -306,8 +306,7 @@ commit_loose_object_trusted (OstreeRepo        *self,
             goto out;
         }
 
-      if (objtype == OSTREE_OBJECT_TYPE_FILE && (self->mode == OSTREE_REPO_MODE_BARE ||
-                                                 self->mode == OSTREE_REPO_MODE_BARE_USER))
+      if (objtype == OSTREE_OBJECT_TYPE_FILE && _ostree_repo_mode_is_bare (self->mode))
         {
           /* To satisfy tools such as guile which compare mtimes
            * to determine whether or not source files need to be compiled,
@@ -700,7 +699,7 @@ write_object (OstreeRepo         *self,
        * binary with trailing garbage, creating a window on the local
        * system where a malicious setuid binary exists.
        */
-      if ((repo_mode == OSTREE_REPO_MODE_BARE || repo_mode == OSTREE_REPO_MODE_BARE_USER) && temp_file_is_regular)
+      if ((_ostree_repo_mode_is_bare (repo_mode)) && temp_file_is_regular)
         {
           guint64 size = g_file_info_get_size (file_info);
 
index 3fa32336ac21be36610cf7352de76eef011f2fea..adc74c0e84149686e792665c48804b1d4fa6b498 100644 (file)
@@ -2472,7 +2472,7 @@ list_loose_objects_at (OstreeRepo             *self,
 
       if ((self->mode == OSTREE_REPO_MODE_ARCHIVE_Z2
            && strcmp (dot, ".filez") == 0) ||
-          ((self->mode == OSTREE_REPO_MODE_BARE || self->mode == OSTREE_REPO_MODE_BARE_USER)
+          ((_ostree_repo_mode_is_bare (self->mode))
            && strcmp (dot, ".file") == 0))
         objtype = OSTREE_OBJECT_TYPE_FILE;
       else if (strcmp (dot, ".dirtree") == 0)
@@ -2743,8 +2743,7 @@ _ostree_repo_read_bare_fd (OstreeRepo           *self,
 {
   char loose_path_buf[_OSTREE_LOOSE_PATH_MAX];
 
-  g_assert (self->mode == OSTREE_REPO_MODE_BARE ||
-            self->mode == OSTREE_REPO_MODE_BARE_USER);
+  g_assert (_ostree_repo_mode_is_bare (self->mode));
 
   _ostree_loose_path (loose_path_buf, checksum, OSTREE_OBJECT_TYPE_FILE, self->mode);